QandA 2025_ii
What is Java?
Java is a high-level, object-oriented, platform-independent programming language.
Why is Java platform-independent?
Java code is compiled into bytecode, which runs on JVM, making it platform-independent.
Differentiate among JDK, JRE, JVM.
- JDK: Java Development Kit (compiler + libraries).
- JRE: Java Runtime Environment (libraries + JVM).
- JVM: Java Virtual Machine (runs bytecode).
Differentiate between == vs .equals()?
== checks reference equality; .equals() checks object content.
What are Java keywords?
Reserved words with special meaning, e.g., class, public, static.
What are literals?
Fixed values in code, e.g., 10, 'A', "Hello".
Explain different Data types found in Java.
Primitive: int, float, char, boolean; Reference: objects, arrays, Strings.
Compare Primitive with Reference types:
Primitive stores value; Reference stores memory address.
What is type casting in Java?
Implicit (widening): int -> double; Explicit (narrowing): double -> int.
What are the default values of primitive data types?
int=0, float=0.0, boolean=false, char='\u0000', object=null
List different types of operators.
- Arithmetic,
- Relational,
- Logical,
- Assignment,
- Unary,
- Ternary,
- Bitwise
compare ++i with i++.
++i: increment then use; i++: use then increment
Comapre if with switch.
if evaluates conditions; switch evaluates expressions against values
What are for, while, do-while?
- for: known iterations
- while: condition first
- do-while: executes at least once
Compare break with continue
break: exit loop; continue: skip current iteration
Write syntax of ternary operator.
condition ? value1 : value2
What are short-circuit operators?
&& and || stop evaluation once result is determined
What is a class and an object?
Class: blueprint; Object: instance of a class
Compare instance with class (static) variables:
Instance: per object; Static: shared by all objects
What is a constructor?
Special method to initialize objects
What are the different types of constructors?
- Default (no args), Parameterized (with args), Copy constructor
- Method overloading vs overriding
- Overloading: same name, different parameters
- Overriding: same name, same parameters, subclass changes behavior
What are static and instance methods?
Static: belongs to class; Instance: belongs to object
What are final, finally, finalize?
- final: constant or immutable
- finally: executes after try-catch
- finalize(): called before garbage collection
List access modifiers?
public, private, protected, default (package-private)
What is inheritance?
Mechanism to acquire properties of another class (types: single, multilevel, hierarchical)
What is polymorphism?
Ability of object to take multiple forms; compile-time (overloading) & runtime (overriding)
What is abstraction?
Hiding implementation; implemented using abstract classes or interfaces
What is encapsulation?
Wrapping data & methods; achieved using private fields and public getters/setters
Compare Abstract class with Interface?
Abstract: can have implemented methods; Interface: only abstract/default/static methods
What are exceptions?
Runtime errors disrupting program flow
Compare Checked with Unchecked exceptions?
Checked: compile-time (IOException); Unchecked: runtime (NullPointerException)
What are try, catch, finally blocks?
try: code to test, catch: handle exception, finally: always executes
Compare throw with throws?
throw: throw single exception; throws: declare exceptions in method signature
What is custom exception?
User-defined class extending Exception or RuntimeException
What are String and StringBuilder/StringBuffer?
String: immutable; StringBuilder/StringBuffer: mutable (Buffer is synchronized)
What are wrapper classes?
Convert primitive to object, e.g., int->Integer, double->Double
What are Collections?
Framework for storing objects: List, Set, Map, Queue
Compare ArrayList with LinkedList.
ArrayList: fast random access; LinkedList: fast insert/delete
What are HashMap and TreeMap?
HashMap: unordered; TreeMap: sorted keys
What are Set, List, Map?
List: ordered, duplicates allowed; Set: no duplicates; Map: key-value pairs
What is multithreading?
Multiple threads executing concurrently
What are Runnable and Thread?
Runnable: implement interface; Thread: extend class
What is Synchronization?
Control access to shared resources to prevent race conditions
Waht is Lambda expression?
Short syntax for implementing functional interfaces
compare == with .equals() for objects.
== compares references; .equals() compares content
What is Serialization?
Converting object into byte stream for storage or transmission
What are Annotations?
Metadata added to code, e.g., @Override, @Deprecated
What isGarbage collection?
Automatic memory management by JVM
Compare == operator for primitives with references.
Primitives: value comparison; References: address comparison